-
Notifications
You must be signed in to change notification settings - Fork 998
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Execution-ified fork choice, draft 1 #1068
Conversation
Looking at this today. (Assigned PR to myself to avoid conflicts with other reviewers.) Edit: This PR addresses points 1, 3, 4, 5, 6, 9, 10 of issue #1053. |
reviewing now! please don't merge even though "approved" |
We probably want a couple tests before merging. |
Changelog:
It's blocking by the new SSZ |
I don't think we need Store to be an SSZ object. It's not a consensus object. |
if state.current_justified_epoch > slot_to_epoch(store.blocks[store.justified_root].slot): | ||
store.justified_root = state.current_justified_root | ||
if state.previous_justified_epoch > slot_to_epoch(store.blocks[store.justified_root].slot): | ||
store.justified_root = state.previous_justified_root |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I think it's impossible of that both
state.current_justified_epoch > slot_to_epoch(store.blocks[store.justified_root].slot)
andstate.previous_justified_epoch > slot_to_epoch(store.blocks[store.justified_root].slot)
happen? - IMHO it's better to avoid using the possible updated
store.justified_root
in the second condition check (if state.previous_justified_epoch > ...
), it looks confusing.
Suggestion:
if state.current_justified_epoch > slot_to_epoch(store.blocks[store.justified_root].slot):
store.justified_root = state.current_justified_root
elif state.previous_justified_epoch > slot_to_epoch(store.blocks[store.justified_root].slot):
store.justified_root = state.previous_justified_root
👍 An option: if we upgrade the CI to Python 3.7 env (it's currently Python 3.6), we can use @dataclass
class Store:
blocks: Dict[Bytes32, BeaconBlock] = {}
states: Dict[Bytes32, BeaconState] = {}
time: int = 0
latest_targets: Dict[int, Target] = {}
justified_root: Bytes32 = ZERO_HASH
finalized_root: Bytes32 = ZERO_HASH |
```python | ||
def on_block(store: Store, block: BeaconBlock) -> None: | ||
# Check block is a descendant of the finalized block | ||
assert get_ancestor(store, signing_root(block), store.blocks[store.finalized_root].slot) == store.finalized_root |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The given block
hasn't been stored yet here, so inside get_ancestor
, it can't access the given block
from store
.
As a beacon node, I support it needs to store the block before these verifications?
pre_state = store.states[block.parent_root] | ||
assert store.time >= pre_state.genesis_time + block.slot * SECONDS_PER_SLOT | ||
# Check the block is valid and compute the post-state | ||
state = state_transition(pre_state, block) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhhh a mutability issue here! 💣
state_transition
returns astate
, but note that there is side effect - the givenstate
input would be changed anyway. (Avoid side effect in state transition with mutable object #1059)- Since
store.states
is adict
, the updatedpre_state
would mess upstore.states
.
A quick fix for this PR might still be adding the scary deepcopy
inside state_transition
that I know people really don't want to have in the spec. :'(
But open to continue discussing in #1059.
1. Make `Target` as a dataclass 2. Fix `on_attestation` typos 3. Add basic tests TBD: 1. deepcopy? 2. Add new block to the store before validation
Changelog:
TBD: to confirm if |
Is anyone still working on this? Shall I take a look? (Other fork-choice implementation work here: https://github.com/protolambda/lmd-ghost/). |
Please do :) No one seems to have taken "merge responsibility" for this one. |
Not tested at all. Also missing one optimization that's probably crucial to have even enough efficiency for testing, which is a children cache.
Also missing weak-subjectivity-aware safety measurement and time-aware justified head switching.